package com.wzy.netty.nio.zerocopy;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

/**
 * 描述
 * 创建人    Wzy
 * 创建时间: 2020-05-21  1:27
 */
public class NewIOClient {
    public static void main(String[] args) throws IOException {
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress("localhost", 7001));
        String fileName = "";

        FileChannel fileChannel = new FileInputStream(fileName).getChannel();

        //准备发送
        long start = System.currentTimeMillis();

        //transferTo底层采用了零拷贝
        long l = fileChannel.transferTo(0, fileChannel.size(), socketChannel);
        System.out.println("发送总的字节数=" + l + "耗时:" + (System.currentTimeMillis() - start));

    }
}
